package com.saya.servlet;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.EntityNotFoundException;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.saya.utils.Constant;

@SuppressWarnings("serial")
public class TestServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
		String token = req.getParameter(Constant.TOKEN);

		Key k = KeyFactory.stringToKey(token);
		try {
			System.out.println(k.getId());
			Entity e = ds.get(k);
			resp.getWriter().print(e.getProperty("LoginDate"));
		} catch (EntityNotFoundException e) {
			e.printStackTrace();
		}
	}
}
